<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<button type="button" id="btn">11</button>
	</body>
	<script type="text/javascript">
		function flash() {
			var r = Math.floor(Math.random() * 255);
			var g = Math.floor(Math.random() * 255);
			var b = Math.floor(Math.random() * 255);
			document.body.style.backgroundColor = `rgb(${r},${g},${b})`;
		}
		window.addEventListener('resize',throttle(flash,2000))
		
		function throttle(func,delay){
			var pre = 0;
			return function() {
				var now = Date.now();
				if(now - pre > delay) {
					func();
					pre = now;
				} 
			}
		}
		
		
		var btn = document.getElementById("btn");
		function payMoney() {
			console.log("已买");
		}
		function debounce(func,delay) {
			var timer;
			return function(){
				var that = this;
				var args = arguments;
				clearTimeout(timer)
				var timer = setTimeout(function(){
					func.apply(that,args)
				},delay);
			}
		}
		btn.addEventListener("click",debounce(payMoney,2000))
	</script>
</html>
